package com.zjitc;

import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/6 14:00
 * @description:
 */
public class App2 {

  public static void main(String[] args) {
    HikariDataSource dataSource= null;
    try {

      dataSource=new HikariDataSource();
    dataSource.setUsername("root");
    dataSource.setPassword("123456789");
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test");
      try {

        Connection connection =dataSource.getConnection();
        System.out.println(connection);
      }catch (SQLException e){
        e.printStackTrace();
      }
    }finally {
      if (dataSource!=null){
        dataSource.close();
      }
    }

    //ApplicationContext context =new ClassPathXmlApplicationContext("hikariCP-spring-config.xml");
    //DataSource bean= context.getBean(DataSource.class);
    //try {
    //  Connection connection =bean.getConnection();
    //  System.out.println(connection);
    //}catch (SQLException e){
    //  e.printStackTrace();
    //}
  }
}
